package com.john.permission.pojo;

import com.john.permission.common.util.GlobalSystemConstants;
import lombok.*;

/**
 * 返回Ajax请求数据
 */
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class AjaxResponsePOJO {
    private int code;
    private String msg;
    private Object data;

    public static class Builder {
        private int code;
        private String msg;
        private Object data;
        public Builder code(int code) {
            this.code = code;
            return this;
        }
        public Builder msg(String msg) {
            this.msg = msg;
            return this;
        }
        public Builder data(Object data) {
            this.data = data;
            return this;
        }
        public AjaxResponsePOJO build() {
            return new AjaxResponsePOJO(this.code, this.msg, this.data);
        }

        public AjaxResponsePOJO error(String msg) {
            return new AjaxResponsePOJO(GlobalSystemConstants.HTTP_CODE_COMMON_ERROR, msg, null);
        }

        public AjaxResponsePOJO error(Object data) {
            return new AjaxResponsePOJO(GlobalSystemConstants.HTTP_CODE_COMMON_ERROR, null, data);
        }

        public AjaxResponsePOJO error(String msg, Object data) {
            return new AjaxResponsePOJO(GlobalSystemConstants.HTTP_CODE_COMMON_ERROR, msg, data);
        }

        public AjaxResponsePOJO ok(String msg) {
            return new AjaxResponsePOJO(GlobalSystemConstants.HTTP_CODE_SUCCESS, msg, null);
        }

        public AjaxResponsePOJO ok(Object data) {
            return new AjaxResponsePOJO(GlobalSystemConstants.HTTP_CODE_SUCCESS, null, data);
        }

        public AjaxResponsePOJO ok(String msg, Object data) {
            return new AjaxResponsePOJO(GlobalSystemConstants.HTTP_CODE_SUCCESS, msg, data);
        }

    }
}
